import 'babel-polyfill'
import Vue from 'vue'
import router from './routers'
import VueLazyLoad from 'vue-lazyload'
import './scss/base.scss'
import './components'
import App from './App'
import store from './store'
import './common/filter'
import { session } from 'js/util'

// 懒加载
Vue.use(VueLazyLoad, {
  attempt: 1
})

Vue.config.productionTip = false

// 判断是否已登录，若未登录，则跳转登录页 
router.beforeEach((to, from, next) => {
  if (to.meta.isAuth) {
    const userInfo = session.get('userInfo') || {}
    if (userInfo.token) {
      next()
    } else {
      next({
        path: '/login'
      })
    }
  } else {
    next()
  }
})

export default new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
